/*Hdip Project 2013-14, Student Name:- Chris Pembroke,  Student Number:- x00115839*/

function init() {
    var selecteditems = document.getElementById("SelectedItems");

    var tempvar1 = selecteditems.value;
    var temparr1 = tempvar1.split(";");

    var list = document.getElementById("ServiceItems");
    var newListItem = document.createElement('OPTION');

    for (i = 0; i < (temparr1.length - 1) ; i++) {
        var list = document.getElementById("ServiceItems");
        var newListItem = document.createElement('OPTION');
        newListItem.text = temparr1[i];
        newListItem.value = temparr1[i];
        list.add(newListItem);
    }

}
document.addEventListener("DOMContentLoaded", init, false);



function AddListItem() {
    var itemsSelectedItem = document.getElementById("Items");
    var itemSelected = itemsSelectedItem.options[itemsSelectedItem.selectedIndex].text;

    var actionSelectedItem = document.getElementById("Actions");
    var actionSelected = actionSelectedItem.options[actionSelectedItem.selectedIndex].text;

    var itemaction = actionSelected + " - " + itemSelected;

    var list = document.getElementById("ServiceItems");
    var newListItem = document.createElement('OPTION');
    newListItem.text = itemaction;
    newListItem.value = itemaction;
    list.add(newListItem);

    var allSelectedItems = "";

    var list = document.getElementById("ServiceItems");
    for (var i = 0; i < list.options.length; i++) {

        allSelectedItems += list.options[i].value + ";\n";
    }
    var textarea = document.getElementById("SelectedItems");
    textarea.value = allSelectedItems;

}

function RemoveListItem() {

    var list = document.getElementById("ServiceItems");

    if (list.options.length > 0) {

        for (var i = list.options.length - 1; i >= 0; i--) {
            if (list.options[i].selected) {
                list.remove(i);

                var allSelectedItems = "";
                var list = document.getElementById("ServiceItems");
                for (var i = list.options.length - 1; i >= 0; i--) {
                    allSelectedItems += list.options[i].value + ";\n";
                }
                var textarea = document.getElementById("SelectedItems");
                textarea.value = allSelectedItems;

                return false;
            }
        }
    }
    else {
        alert("Unable to remove as List Empty");
    }
}

function calcTotalPrice() {
    var partsCost = document.getElementById("PartsCost");
    var labourCost = document.getElementById("LabourCost");
    var totalCost = document.getElementById("TotalPrice");
    if (isNaN(partsCost.value))
    {
        partsCost.value = 0.0;
    }
    if (isNaN(labourCost.value))
    {
        labourCost.value = 0.0;
    }
    totalCost.value = parseFloat(labourCost.value) + parseFloat(partsCost.value);
}


$(document).ready(function () {

    $("input#Date").datepicker();

    $("#btn1").click(function () {
        $("#StatusBikeInShop").val("In Shop");
    });

    $("#btn2").click(function () {
        $("#StatusBikeInShop").val("Not In Shop");
    });

    $("#btn3").click(function () {
        $("#StatusBikeInShop").val("Collected");
    });

    $("#btn4").click(function () {
        $("#StatusService").val("Quote");
    });

    $("#btn5").click(function () {
        $("#StatusService").val("Booked");
    });

    $("#btn6").click(function () {
        $("#StatusService").val("Cancelled");
    });

    $("#btn7").click(function () {
        $("#StatusService").val("Done");
    });

    $("#btn8").click(function () {
        $("#StatusService").val("Paid");
    });
});




    
	